// var app = getApp(),
//     util = require("../../utils/util.js");
var qqmapsdk, _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function(t) {
        return typeof t;
    } : function(t) {
        return t && "function" == typeof Symbol && t.constructor === Symbol && t !== Symbol.prototype ? "symbol" : typeof t;
    },
    app = getApp(),
    util = require("../../utils/util.js"),
    QQMapWX = require("../../utils/qqmap-wx-jssdk.js");

Page({
    data: {},
    onLoad: function(n) {
        var a = this,
            e = wx.getStorageSync("users").id;
        app.setNavigationBarColor(this);

        app.util.request({
            url: "entry/wxapp/system",
            cachetime: "0",
            success: function(t) {
                qqmapsdk = new QQMapWX({
                    key: t.data.map_key
                });
            }
        });
        app.util.request({
            url: "entry/wxapp/MyAddress",
            cachetime: "0",
            data: {
                user_id: e
            },
            success: function(e) {
                for (var t = 0; t < e.data.length; t++) e.data[t].address = e.data[t].area.join("") + e.data[t].address;
                a.setData({
                    address_list: e.data
                });
            }
        });
    },
    relocation_back: function() {
        wx.navigateBack();
    },
    relocation: function() {
        this.setData({
            is_Refresh: true
        })
        this.onShow();
    },
    onShow: function() {
        var i = this;
        let index__address = wx.getStorageSync("index_addresses");
        if (index__address) {
            i.setData({
                addresses: index__address
            });
        }
        wx.getLocation({
            type: "wgs84",
            success: function(t) {
                var e = t.latitude,
                    s = t.longitude;
                qqmapsdk.reverseGeocoder({
                    location: {
                        latitude: e,
                        longitude: s
                    },
                    coord_type: 1,
                    success: function(t) {
                        index__address == '' ? t.result.formatted_addresses.recommend : index__address
                        i.setData({
                            addresses: index__address
                        });
                        if (i.data.is_Refresh) {
                            wx.setStorageSync("index_Refresh", true)
                            wx.setStorageSync("index_lat", e)
                            wx.setStorageSync("index_lng", s)
                            wx.setStorageSync("index_addresses", t.result.formatted_addresses.recommend);
                        }
                    }
                });
            }
        });
    },
    ChoiceAddress: function(t) {
        let lat = t.currentTarget.dataset.lat,
            lng = t.currentTarget.dataset.lng,
            addresses = t.currentTarget.dataset.addresses;
        wx.setStorageSync("index_Refresh", true)
        wx.setStorageSync("index_lat", lat)
        wx.setStorageSync("index_lng", lng)
        wx.setStorageSync("index_addresses", addresses);
        wx.navigateBack();
    },
    dingwei: function(e) {
        let a = this;
        wx.getLocation({
            type: 'gcj02', //返回可以用于wx.openLocation的经纬度
            success(res) {
                let latitude = res.latitude,
                    longitude = res.longitude;
                wx.chooseLocation({
                    success: function(e) {
                        // let t = e.address.indexOf("区");
                        if (e.address == ''){
                            wx.showToast({
                                title: '您没选择地址，请重新选择！',
                                icon: 'none',
                                duration: 2500
                            });
                            return false;
                        }
                        wx.setStorageSync("index_Refresh", true)
                        wx.setStorageSync("index_lat", e.latitude)
                        wx.setStorageSync("index_lng", e.longitude)
                        wx.setStorageSync("index_addresses", e.address);
                        wx.navigateBack();
                    },
                    fail: function() {
                        wx.getSetting({
                            success: function(e) {
                                e.authSetting["scope.address"] ? console.log("取消") : '';
                            }
                        });
                    }
                });
            }
        })
    },
});